package com.hexinfo.dmpro.common.base;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class BaseRequest {
    private Long id; // 主键
    private String blurry; // 模糊查询值
    private String createTimeStart; // 创建日期开始
    private String createTimeEnd; // 创建日期结束
    private String createBy; // 创建者
    private String lastUpdateTimeStart; // 最后修改日期开始
    private String lastUpdateTimeEnd; // 最后修改日期结束
    private String lastUpdateBy; // 最后修改者

    public static BaseRequest viewToRequest(BaseView view) {
        BaseRequest request = new BaseRequest();
        request.setId(view.getId());
        request.setBlurry(view.getBlurry());
        List<String> createTime = view.getCreateTime();
        if (createTime != null) {
            if (createTime.size() >= 1) {
                request.setCreateTimeStart(createTime.get(0));
            }
            if (createTime.size() == 2) {
                request.setCreateTimeEnd(createTime.get(1));
            }
        }
        request.setCreateBy(view.getCreateBy());
        List<String> lastUpdateTime = view.getLastUpdateTime();
        if (lastUpdateTime != null) {
            if (lastUpdateTime.size() >= 1) {
                request.setLastUpdateTimeStart(lastUpdateTime.get(0));
            }
            if (lastUpdateTime.size() == 2) {
                request.setLastUpdateTimeEnd(lastUpdateTime.get(1));
            }
        }
        request.setLastUpdateBy(view.getLastUpdateBy());
        return request;
    }
}
